package com.accenture.job.executor.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

/**
 * AI数据Mapper
 * 
 * @author binbin.a.zhang
 */
@Mapper
public interface AIMapper {
	/**
	 * 新增数据到 [TE_AI_AttendanceExpense] AI_Share_DB
	 * 
	 * @return insertRowCount
	 * @author binbin.a.zhang
	 */

	@Insert(" insert into [AI_Share_DB].[dbo].[TE_AI_AttendanceExpense]"
			+ "	select a.ReferenceNo,b.No,d.code ,c.company,GETDATE() as CreateDateTime "
			+ " from [TE_APP_DEV].[dbo].TE_WA_OriginalReimbursement a, "
			+ " [TE_APP_DEV].[dbo].TE_WA_OriginalExpenseElement b, "
			+ " [TE_APP_DEV].[dbo].TE_WA_OriginalExpenseParticipant c , "
			+ " [TE_APP_DEV].[dbo].TE_MD_ExpenseType d "
			+ " where a.ReimbursementId=b.ReimbursementId and b.ExpenseId=c.ExpenseId"
			+ " and d.ExpenseTypeId=b.ExpenseTypeId ")
	int aiAttendanceExpense();

	/**
	 * 新增数据到 [TE_AI_SELLERNAMEEXPENSE] AI_Share_DB
	 * 
	 * @return insertRowCount
	 * @author binbin.a.zhang
	 */

	@Insert(" INSERT INTO [AI_SHARE_DB].[DBO].[TE_AI_SELLERNAMEEXPENSE] "
			+ " SELECT A.REFERENCENO,B.NO,c.code,B.VENDORNAME,GETDATE() AS CREATEDATETIME "
			+ " FROM [TE_APP_DEV].[DBO].TE_WA_ORIGINALREIMBURSEMENT A,"
			+ " [TE_APP_DEV].[DBO].TE_WA_ORIGINALEXPENSEELEMENT B ,"
			+ " [TE_APP_DEV].[dbo].TE_MD_ExpenseType c" 
			+ " WHERE A.REIMBURSEMENTID=B.REIMBURSEMENTID and c.ExpenseTypeId=b.ExpenseTypeId")
	int aiSellerNameExpense();

	/**
	 * 同步 [TE_AI_AttendanceExpenseResult] AI_Share_DB->ITE
	 * 
	 * @return insertRowCount
	 * @author binbin.a.zhang
	 */

	@Insert("  INSERT INTO TE_APP_DEV.DBO.TE_RU_AIVERIFICATIONRESULT "
			+ " SELECT GETDATE() AS CREATEDATETIME,EXPENSENO,REFERENCENO,ATTENDANCECOMPANYNAME,1 "
			+ " FROM AI_SHARE_DB.DBO.TE_AI_ATTENDANCEEXPENSERESULT  WHERE RESULTVALUE=1 ")
	int SynchronousAttendanceExpenseResult();

	/**
	 * 同步 [TE_AI_sellerNameExpenseResult] AI_Share_DB->ITE
	 * 
	 * @return insertRowCount
	 * @author binbin.a.zhang
	 */

	@Insert("insert into TE_APP_DEV.dbo.TE_RU_AiVerificationResult "
			+ " select GETDATE() as CreateDateTime,ExpenseNo,ReferenceNo,SellerName,2 "
			+ " from AI_Share_DB.dbo.TE_AI_SellerNameExpenseResult  where ResultValue=2")
	int SynchronousSellerNameExpenseResult();

	/**
	 * 删除 AIAttendanceExpenseResult数据
	 * 
	 * @return void
	 * @author binbin.a.zhang
	 */
	@Delete("truncate table AI_Share_DB.dbo.TE_AI_AttendanceExpenseResult ")
	void deleteAttendanceExpenseResult();

	/**
	 * 删除 AISellerNameExpenseResult数据
	 * 
	 * @return void
	 * @author binbin.a.zhang
	 */
	@Delete("truncate table AI_Share_DB.dbo.TE_AI_SellerNameExpenseResult ")
	void deleteSellerNameExpenseResult();
}
